import "../../node_modules/utils-lib-js/dist/umd/index.js";
import { Client } from "../../dist/esm/index.js";

const init = async () => {
  const client = new Client({
    target: self,
    source: self,
    handlers: {
      // 子页面的处理函数
      worker2info: console.info,
    },
  });
  // 建立连接
  client.mount();
  // 监听 "msg" 事件
  client.on("msg", console.log.bind(null, "worker2收到消息"));
  client.invokeHandler({ type: "worker1info", data: ["worker2"] });
  client.invokeHandler({ type: "log", data: ["worker2"] });
  client.send({ type: "msg", data: { name: "worker2" } });
};
init();
